package com.JFapp.controller;


import com.JFapp.constants.SystemConstants;
import com.JFapp.domain.dto.AddCommentDto;
import com.JFapp.domain.entity.Comment;
import com.JFapp.domain.entity.ResponseResult;
import com.JFapp.service.CommentService;
import com.JFapp.utils.BeanCopyUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/comment")
@Api("评论管理")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @ApiOperation("评论列表")
    @GetMapping("/commentList")
    public ResponseResult commentList(Long articleId, Integer pageNum, Integer pageSize){
        return commentService.commentList(SystemConstants.ARTICLE_COMMENT,articleId,pageNum,pageSize);
    }

    @ApiOperation("添加评论")
    @PostMapping
    public ResponseResult addComment(@RequestBody AddCommentDto commentDto){
        Comment comment = BeanCopyUtils.copyBean(commentDto, Comment.class);
        return commentService.addComment(comment);
    }

    @ApiOperation("查询子评论")
    @GetMapping("/linkCommentList")
    public  ResponseResult linkCommentList(Integer pageNum, Integer pageSize){
        return commentService.commentList(SystemConstants.LINK_COMMENT,null,pageNum,pageSize);
    }

}
